package org.come.Jpanel;

import com.tool.btn.GetLiangHaoBtn;
import com.tool.btn.LiangHaoItemBtn;
import com.tool.tcpimg.UIUtils;
import com.updateNew.MyIsif;
import org.apache.commons.lang.StringUtils;
import org.come.bean.SearchSellLiangHaoResultBean;

import javax.swing.*;
import java.awt.*;
import java.awt.geom.RoundRectangle2D;

public class GetLiangHaoOneJpanel extends JPanel {

    private static final long serialVersionUID = 1L;

    ImageIcon bg1;
    ImageIcon bg2;

    ImageIcon itemBg,fengexian;
    private JLabel searchTitle, text1, text2;
    private JTextField searchText;
	private GetLiangHaoBtn btnSearch;

    private LiangHaoItemBtn[] liangHaoListBtn;

    private SearchSellLiangHaoResultBean slb;
    private Color color = new Color(56, 53, 46, 238);
    public GetLiangHaoOneJpanel() {
        System.out.println(MyIsif.getStyle());
        this.setPreferredSize(new Dimension(697, 538));
        this.setLayout(null);
        this.setOpaque(false);
        this.bg1 = new ImageIcon("inkImg/newbackground/LiangHaoOneBg1.png");
        this.bg2 = new ImageIcon("inkImg/newbackground/LiangHaoOneBg3.png");
        this.itemBg = new ImageIcon("inkImg/newbutton/198.png");
        this.fengexian = new ImageIcon("inkImg/newbutton/fengexian.png");

//        searchText = new JTextField();
//        searchText.setBounds(200, 75, 100, 26);
//        this.add(searchText);

        searchTitle = new JLabel();
        searchTitle.setText("搜索");
        searchTitle.setBounds(170, 75, 100, 26);
        searchTitle.setFont(UIUtils.TXT_hyzjt18);
        searchTitle.setVerticalTextPosition(SwingConstants.CENTER);
        searchTitle.setHorizontalTextPosition(SwingConstants.CENTER);
        this.add(searchTitle);

        text1 = new JLabel();
        text1.setText("【规则说明】");
        text1.setBounds(170, 100, 100, 26);
        text1.setFont(UIUtils.TEXT_FONT14);
        text1.setVerticalTextPosition(SwingConstants.CENTER);
        text1.setHorizontalTextPosition(SwingConstants.CENTER);
        this.add(text1);

        text2 = new JLabel();
        text2.setText("可以自选非5A的6位数靓号");
        text2.setBounds(170, 120, 300, 26);
        text2.setFont(UIUtils.TEXT_FONT14);
        text2.setVerticalTextPosition(SwingConstants.CENTER);
        text2.setHorizontalTextPosition(SwingConstants.CENTER);
        this.add(text2);

		btnSearch = new GetLiangHaoBtn("inkImg/newbutton/188.png", 1,"" ,10, this);
		//btnSearch.setText("搜索");
		btnSearch.setBounds(316, 79, 20, 20);
		this.add(btnSearch);

        this.liangHaoListBtn = new LiangHaoItemBtn[16];
        for (int i = 1; i <= 16; i++) {
            liangHaoListBtn[i-1] = new LiangHaoItemBtn("inkImg/newbutton/189.png",1,1,null,null);
            int line = (i-1)/4;
            int index = (i-1)%4;
            liangHaoListBtn[i-1].setBounds(170 + 158 * index,239 + 68 * line,27,27);
            this.add(liangHaoListBtn[i-1]);
        }
        Font font = new Font("微软雅黑", 0, 14);
        searchText = new JTextField() {
            @Override
            protected void paintComponent(final Graphics g) {
                Graphics2D g2d = (Graphics2D) g.create();
                g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
                RoundRectangle2D roundedRectangle = new RoundRectangle2D.Double(0, 0, this.getWidth(), this.getHeight(), 5, 5);
                g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.8f));
                g2d.setColor(color);
                g2d.fill(roundedRectangle);
                g2d.setColor(Color.white);
                super.paintComponent(g);
            }
        };
        searchText.setForeground(Color.white);
        searchText.setBackground(UIUtils.Color_BACK);
        searchText.setBorder(BorderFactory.createEmptyBorder());
        searchText.setCaretColor(Color.WHITE);
        searchText.setFont(font);
        searchText.setBounds(215, 80, 120, 18);
        this.add(searchText);
    }

    @Override
    protected void paintComponent(Graphics g) {
        super.paintComponent(g);
        g.drawImage(this.bg2.getImage(), 45, 65, 630, 135, null);
        g.drawImage(this.bg1.getImage(), 68, 30, 81, 207, null);
        g.drawImage(this.fengexian.getImage(), 45, 210, 630, 2, null);

        if(this.slb!=null && slb.getSellLiangHaos()!=null && slb.getSellLiangHaos().size()>0){
            for(int i=1; i<= slb.getSellLiangHaos().size(); i++){
                int line = (i-1)/4;
                int index = (i-1)%4;
                g.drawImage(this.itemBg.getImage(),45 + 158 * index,220 + 68 * line,156,66,null);
                g.setColor(new Color(79,79,79));
                g.setFont(new Font("汉仪中楷简",1,22));
                g.drawString( slb.getSellLiangHaos().get(i-1).getLianghao(),60 + 158 * index,245 + 68 * line);
                g.setFont(new Font("汉仪中楷简",0,14));
                g.drawString( "积分：",60 + 158 * index,270 + 68 * line);
                g.setColor(new Color(255, 0, 0));
                g.drawString(String.valueOf(slb.getSellLiangHaos().get(i-1).getPrice()),100 + 158 * index,270 + 68 * line);
                this.liangHaoListBtn[i-1].setLianghaoItem(slb.getSellLiangHaos().get(i-1));
            }
        }


        if( this.slb!=null && this.slb.getSellLiangHaos()!=null ){

            for(int i = 0 ;i< this.slb.getSellLiangHaos().size();i++){
                this.liangHaoListBtn[i].setVisible(true);
            }

            for(int i = this.slb.getSellLiangHaos().size();i<liangHaoListBtn.length;i++){
                this.liangHaoListBtn[i].setVisible(false);
            }
        }


        for(int j=0;j<liangHaoListBtn.length;j++){
            if(liangHaoListBtn[j].getLianghaoItem() == null || StringUtils.isEmpty(liangHaoListBtn[j].getLianghaoItem().getLianghao())){
                this.liangHaoListBtn[j].setVisible(false);
            }
        }
    }

    public void changeFrom(int caozuo) {

    }


    public JTextField getSearchText() {
        return searchText;
    }

    public void setSearchText(JTextField searchText) {
        this.searchText = searchText;
    }

    public SearchSellLiangHaoResultBean getSlb() {
        return slb;
    }

    public void setSlb(SearchSellLiangHaoResultBean slb) {
        for(int j=0;j<liangHaoListBtn.length;j++){
            this.liangHaoListBtn[j].setLianghaoItem(null);
        }
        this.slb = slb;
    }

    public void resetTableData(SearchSellLiangHaoResultBean sa){


    }
}
